﻿using System;
using libEngineAI.Interfaces;
using libEngineAI;

namespace libGameCheckers
{
	public class HumanPlayer : IPlayer
	{
		#region IPlayer implementation

		public Movement GetMovement( IGame Game )
		{
			Movement mov = null;

			while( mov == null )
			{
				int ActualX = Console.CursorLeft;
				int ActualY = Console.CursorTop;

				ConsoleKeyInfo k = Console.ReadKey();

				switch( k.Key )
				{
					case ConsoleKey.LeftArrow:
						if( Console.CursorLeft > 4 )
							Console.CursorLeft = Console.CursorLeft - 4;
						else
							Console.CursorLeft = 3;

						break;

					case ConsoleKey.UpArrow:
						if( Console.CursorTop > 3 )
						{
							Console.CursorTop = Console.CursorTop - 1;
							Console.CursorLeft = Console.CursorLeft - 1;
						}
						else
							Console.CursorLeft = Console.CursorLeft - 1;

						break;

					case ConsoleKey.RightArrow:
						if( Console.CursorLeft < ( Game.Board.MaxCoordinates.x * 3 ) + 1 )
							Console.CursorLeft = Console.CursorLeft + 2;
						else
							Console.CursorLeft = Game.Board.MaxCoordinates.x * 3;

						break;

					case ConsoleKey.DownArrow:
						if( Console.CursorTop < ( Game.Board.MaxCoordinates.y ) + 2 )
						{
							Console.CursorTop = Console.CursorTop + 1;
							Console.CursorLeft = Console.CursorLeft - 1;
						}
						else
							Console.CursorLeft = Console.CursorLeft - 1;

						break;

					case ConsoleKey.Enter:
						Console.CursorTop = ActualY;
						Console.CursorLeft = ActualX;



						break;

					default:
						Game.Board.Refresh();
						break;
				}
			}

			return mov;
		}

		public libEngineAI.PlayerType PlayerType { get; set; }

		#endregion
	}
}

